﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Guedes_Library;

public partial class clientes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["p"] == null)
        {
            Response.Redirect("clientes.aspx?p=4");
        }

        if (!Page.IsPostBack)
        {
            Repeater1.DataSource = GetClients();
            Repeater1.DataBind();
        }

    }

    protected List<clients> GetClients()
    {
        List<clients> data;
        using (guedesEntities _db = new guedesEntities())
        {
            data = (from p in _db.clients
                    orderby p.ID descending
                    select p).ToList();

            return data;
        }
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        ImageButton imgbtn = (ImageButton)e.Item.FindControl("imgCliente");
        string url = (e.Item.DataItem as clients).Url;
        if(url.ToUpper().IndexOf("HTTP://") == -1)
            url = "http://"+url;
        imgbtn.ImageUrl = ResolveClientUrl("~/File/thumb/"+(e.Item.DataItem as clients).Image);
        imgbtn.PostBackUrl = url;
    }
}